<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 100px;
            height: 100px;
            background: rgba(94, 221, 185, 0.249);
            position: absolute;
            left: 0px;
            top: 0px;
        }
    </style>
</head>

<body>
    <button>点一下</button>
    <div class="box"></div>
    <script>
        let eventObj = {};
        // import "./b.js";
        // import {c as e,d,obj} from "./a.js"
        // console.log(e);
        // console.log(arguments.callee.toString());
        // console.log(exports)
        // console.log(require)
        // console.log(module)
        // console.log(__filename)
        // console.log(__dirname)

        // import "./a.js";
        // document.querySelector("button").onclick = function() {
        //     import("./b.js").then(res=>{
        //         console.log(res);
        //     })
        // }
        // console.log("请求1");
        // setTimeout(() => {
        //     console.log("111");
        //     console.log("请求2");   
        //     setTimeout(() => {
        //         console.log("222");
        //         console.log("请求3");
        //         setTimeout(() => {
        //             console.log("请求333");
        //             console.log("444");
        //             setTimeout(() => {
        //                 console.log("请求444");
        //                 console.log("555");
        //                 setTimeout(() => {
        //                     console.log("555");
        //                     console.log("666");
        //                     setTimeout(() => {
        //                         console.log("666");
        //                     })
        //                 },1000)
        //             },2000)
        //         },3000)
        //     },4000)
        // },5000)


        // let boxEle = document.querySelector(".box");
        // function move(boxEle,target, dir, cb) {
        //     var timer = setInterval(() => {
        //         let num =parseInt(getComputedStyle(boxEle, null)[dir]);
        //         console.log(num);
        //         let speed = 10 * (target > num?1:-1);
        //         if(num === target) {
        //             clearInterval(timer);
        //             cb();
        //         } else {
        //             boxEle.style[dir] = num + speed + "px";
        //         }
        //     },50)
        // }

        // move(boxEle,300,"left",function() {
        //     move(boxEle,300,"top",function() {
        //         move(boxEle,0,"left",function() {
        //             move(boxEle,0,"top",function() {
        //                 console.log("完成");
        //             })
        //         })
        //     })
        // })

        class MyEvent {
            constructor() {
                this.eventobj = {};
            }
            addEvent(eventName, fn) {
                if(typeof this.eventObj[eventName] === "undefined") {
                    this.eventObj[eventName] = [];
                }
                this.eventObj[eventName].push(fn);

            }
            trigger(eventName) {
                if(typeof this.evenrObj[eventName] !== "undefined") {
                    this.eventObj[eventName].forEach(fn => {
                        fn();
                    })

                } else {
                    throw Error("参数传递错误");
                }
            }
        }

        let myevent = new MyEvent();
        myevent.addEvent("myevent",function() {
            console.log(111);
        })
        myevent.addEvent("myevent",function(){

        })
        setTimeout(() => {
            myevent.trigger("myevent");
        },2000)
    </script>
</body>

</html>